package com.hjx.movie.core.system.controller.admin;

import com.hjx.movie.common.utils.Result;
import com.hjx.movie.common.utils.ResultType;
import com.hjx.movie.core.system.service.admin.ICinemaHallSeatService;
import com.hjx.movie.persistence.system.model.IvyCinemaHallSeat;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>Title:</p>
 * <p>Description:</p>
 *
 * @author hjx
 * @date 2021/2/9 - 22:17
 */
@Slf4j
@RestController
@RequestMapping("/cinemaHallSeat")
public class CinemaHallSeatController {
    @Resource
    private ICinemaHallSeatService cinemaHallSeatService;

    @GetMapping("generate")
    public Result generateSeat(@RequestParam("cinemaHallId") Long cinemaHallId,
                               @RequestParam("maxX") Integer maxX,
                               @RequestParam("maxY") Integer maxY){
        if (cinemaHallSeatService.generatorSeats(cinemaHallId,maxX,maxY)){
            return Result.success("座位生成成功");
        }
        return Result.error(ResultType.USER_INPUT_ERROR,"座位生成失败");
    }

    @GetMapping("findByHallId")
    public Result findSeatByHallId(@RequestParam("cinemaHallId") Long cinemaHallId){
        return Result.success(cinemaHallSeatService.findByCinemaId(cinemaHallId));
    }
    @PostMapping("update")
    public Result update(@RequestBody IvyCinemaHallSeat seat){
        if (cinemaHallSeatService.updateSeat(seat)){
            return Result.success("修改座位成功");
        }
        return Result.error(ResultType.USER_INPUT_ERROR,"修改座位失败");
    }
}
